import turtle

# 数据
def line(x1,x2, y1,y2):
    x = x1; y = y1
    delta_x = abs(x2-x1); delta_y = abs(y2-y1)
    sign_x = 0 if x2==x1 else (1 if x2>x1 else -1)
    sign_y = 0 if y2==y1 else (1 if y2>y1 else -1)
    k0 = -delta_x; k = k0+2*delta_y # k用来判断y是否要增加一个单位。
    pts = []
    for i in range(1, delta_x+1):
        pts.append((x, y))
        if k>=0:
            y += sign_y
            k += (2*delta_y-2*delta_x)
        else: 
            k += 2*delta_y
        x += sign_x
    return pts

pts = line(-100,100, 26,-40)

# 创建画布
turtle.setup(600,600, 300,50)
turtle.pensize(2) # 画笔大小，为1时不成像，遂为2
turtle.speed(0)
turtle.pencolor("blue")

# 画图
turtle.up()
for pt in pts:
    turtle.goto(*pt)
    turtle.down()
    turtle.goto(*pt)
    turtle.up()

# 结束
turtle.hideturtle() # 隐藏画笔箭头
turtle.done()

